package Lee_code;

/**
 * @author blh
 * @date 2024年07月08日 13:56
 */
public class Lee_61_78 {
    public ListNode rotateRight(ListNode head, int k) {
        ListNode dummyHead = new ListNode(-101);
        dummyHead.next = head;
        ListNode temp = dummyHead;
        int count = 0;
        while (temp.next != null) {
            temp = temp.next;
            count++;
        }
        System.out.println("count"+count);
        ListNode tail = temp;
        int realK = k % count;
        ListNode tempPre = dummyHead;
        for (int i = 0; i < k-realK; i++) {
            tempPre = tempPre.next;
        }
        tail.next = dummyHead.next;
        dummyHead.next = tempPre.next;
        tempPre.next = null;
        return dummyHead.next;
    }
}
